var selectedDataRow = '';

$(function () {
    window.actionEvents = {
        'click .isvInfoView': function(e, value, row, index) {
            //编辑操作
            selectedDataRow = row;
            openCommonIsvPage(row.isvPid, 'user');
        },
        'click .infoView': function(e, value, row, index) {
            //编辑操作
            selectedDataRow = row;
            openInfoRecordPage();
        },
    }
    initTextSearch("#isvName",
        basePath + 'bizUserSignedRecords/getIsvData?t='+new Date().getTime()+'&isvName=',
        ['isvPid', 'isvName'],
        {'isvPid':'服务商PID', 'isvName':'服务商名称'},
        'isvPid',
        'isvName',
        true,
        selectIsvValue,
        noSelectIsvValue,
        false);
    initTextSearch("#orgName",
        basePath + 'bizUserSignedRecords/getOrgData?t='+new Date().getTime()+'&orgName=',
        ['orgCode', 'orgName'],
        {'orgCode':'机构编码', 'orgName':'机构名称'},
        'orgCode',
        'orgName',
        true,
        selectOrgValue,
        noSelectOrgValue,
        false);
    laydate.render({
        elem: '#beginTimeStr'
        ,done: function(value, date, endDate){
            //控件选择完毕后的回调
            //点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
            // setAge(value);
        }
    });
});

function selectIsvValue(data) {
    if (!data || !data.isvPid) {
        return;
    }
    $('#isvPid').val(data.isvPid);
}

function noSelectIsvValue() {
    $('#isvPid').val('');
}

function selectOrgValue(data) {
    if (!data || !data.orgCode) {
        return;
    }
    $('#orgCode').val(data.orgCode);
}

function noSelectOrgValue() {
    $('#orgCode').val('');
}

function doRefresh() {
    selectedDataRow = '';
    var userName = $('#userName').val();
    var status = $('#status').val();
    var orgCode = $('#orgCode').val();
    var bizCode = $('#bizCode').val();
    var isvPid = $('#isvPid').val();
    var beginTimeStr = $('#beginTimeStr').val();
    $('#dataTable').bootstrapTable('refresh', {
        url: basePath + 'bizUserSignedRecords/pageFindRecordData?t=' + new Date().getTime(),
        query: {
            userName : userName,
            status : status,
            orgCode : orgCode,
            bizCode : bizCode,
            isvPid : isvPid,
            beginTimeStr : beginTimeStr,
        },
    });
}

function getParams(params) {
    var userName = $('#userName').val();
    var status = $('#status').val();
    var orgCode = $('#orgCode').val();
    var bizCode = $('#bizCode').val();
    var isvPid = $('#isvPid').val();
    var beginTimeStr = $('#beginTimeStr').val();
    return {
        userName : userName,
        status : status,
        orgCode : orgCode,
        bizCode : bizCode,
        isvPid : isvPid,
        beginTimeStr : beginTimeStr,
        pageSize : params.pageSize,
        pageNo : params.pageNumber
    };
}

function openInfoRecordPage() {
    if (!selectedDataRow || selectedDataRow == '') {
        toastr.error(common_no_choose_msg.format("操作"));
        return;
    }
    openPage('info', selectedDataRow.id);
}

function openEditRecordPage() {
    if (!selectedDataRow || selectedDataRow == '') {
        toastr.error(common_no_choose_msg.format("编辑"));
        return;
    }
    openPage('edit', selectedDataRow.id);
}

function openPage(type, id) {
    window.location.href = basePath + 'bizUserSignedRecords/openEditRecordPage?&id=' + id + '&type=' + type + '&t=' + new Date().getTime();
}

function doExport() {
    $('#searchForm').attr("action",basePath+"bizUserSignedRecords/exportRecordDataExcel");
    $('#searchForm').submit();
}

//------------------------------------------------------------------------列表数据初始化

function formatStatus(value, row, index) {
    if (!value || value == '') {
        return '';
    }
    return statusMap[value];
}

//------------------------------------------------------------------------列表选中事件
//上边选中事件
$("#dataTable").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable .success").removeClass("success");
    $(ele).addClass("success");
    selectedDataRow = row;
});
